import request from "../../utils/request.ts";
import {
  AddOrUpdateUser, DoctorResponseData,
  HospitalDepartmentResponseData,
  HospitalDetailResponseData, HospitalDoctorResponseData, HospitalWorkResponseData, LoginData,
  ResponseData,
  UserInfoResponseData, UserResponseData, WXLoginResponseData
} from "./type.ts";

enum API {
  HOSPITAL_DETAIL_URL = '/hosp/hospital/',
  HOSPITAL_DEPARTMENT_URL = '/hosp/hospital/department/',
  GET_USER_CODE_URL = '/sms/send/',
  USER_LOGIN_URL = '/user/login',
  WX_LOGIN_URL = '/user/weixin/getLoginParam',
  HOSPITAL_WORK_URL = '/hosp/hospital/auth/getBookingScheduleRule/',
  HOSPITAL_DOCTOR_URL = '/hosp/hospital/auth/findScheduleList/',
  GET_DOCTOR_URL = '/hosp/hospital/getSchedule/',

  GET_USER_URL = '/user/patient/auth/findAll/',
  CERTIFICATION_TYPE_URL = '/cmn/dict/findByDictCode/',
  SAVE_USER_URL = '/user/patient/auth/save',
  UPDATE_USER_URL = '/user/patient/auth/update',
}

/**
 * ### 获取医院详情
 * @param hoscode 医院编号
 * @return HospitalDetailResponseData 医院详情
 */
export const reqHospitalDetail = (hoscode: string) => {
  return request.get<any, HospitalDetailResponseData>(API.HOSPITAL_DETAIL_URL + hoscode)
}

/**
 * ### 获取医院科室列表
 * @param hoscode 医院编号
 * @return HospitalDepartmentResponseData 医院科室列表
 */
export const reqHospitalDepartment = (hoscode: string) => {
  return request.get<any, HospitalDepartmentResponseData>(API.HOSPITAL_DEPARTMENT_URL + hoscode)
}

/**
 * ### 获取验证码
 * @param phone 手机号
 * @return ResponseData 验证码
 */
export const reqCode = (phone: string) => {
  return request.get<any, ResponseData>(API.GET_USER_CODE_URL + phone)
}

/**
 * ### 登录
 * @param data 登录数据
 * @return UserInfoResponseData 用户信息
 */
export const reqPhoneLogin = (data: LoginData) => {
  return request.post<any, UserInfoResponseData>(API.USER_LOGIN_URL, data)
}

/**
 * ### 微信登录
 * @return WXLoginResponseData 微信登录信息
 */
export const reqWxLogin = (redirectUrl: string) => {
  return request.get<any, WXLoginResponseData>(API.WX_LOGIN_URL + '?wxRedirectUrl=' + redirectUrl);
}

/**
 * ### 获取科室工作详情
 * @param pageNo
 * @param pageSize
 * @param hoscode
 * @param depcode
 * @return HospitalWorkResponseData
 */
export const reqHospitalWork = (pageNo: number, pageSize: number, hoscode: string, depcode: string) => {
  return request.get<any, HospitalWorkResponseData>(API.HOSPITAL_WORK_URL + `${pageNo}/${pageSize}/${hoscode}/${depcode}`);
}
/**
 * ### 获取排班信息
 * @param hoscode
 * @param depcode
 * @param workDate
 * @return HospitalDoctorResponseData
 */
export const reqHospitalDoctor = (hoscode: string, depcode: string, workDate: string) => {
  return request.get<any, HospitalDoctorResponseData>(API.HOSPITAL_DOCTOR_URL + `${hoscode}/${depcode}/${workDate}`);
}

/**
 * ### 获取某一个账号下就诊人信息
 *
 */
export const reqGetUser = () => {
  return request.get<any, UserResponseData>(API.GET_USER_URL);
}
/**
 * ### 获取证件类型
 * @param certificationType
 */
export const reqCertificationType = (certificationType: string = 'CertificationType') => {
  return request.get<any, any>(API.CERTIFICATION_TYPE_URL + certificationType)
}
/**
 * 添加或更新就诊人
 * @param data 就诊人信息
 *
 */
export const reqSaveOrUpdateUser = (data:AddOrUpdateUser)=>{
  if(data.id){
    return request.put<any,any>(API.UPDATE_USER_URL,data);
  }else{
    return request.post<any,any>(API.SAVE_USER_URL,data);
  }
}

export const reqDoctorInfo = (docId:string)=>{
  return request.get<any,DoctorResponseData>(API.GET_DOCTOR_URL+docId);
}
